<?php
namespace AuctionCore\FoursStore;
use AuctionCore\FoursStore\AccountManage;
/**
 * 车辆数量统计
 * @author       shijiabing
 */
class CarCount{
     //初始化
    public function __construct() {           
        parent::__construct();
    }
    /**
     * 查询数量
     * @return [type] [description]
     */
    public function count($params){
        $user_m = new AccountManage();
        $map1 = $user_m->getFourMap();
        $map['suggest_max_price'] = array('gt',0);
        $map['suggest_min_price'] = array('gt',0);
        $map['o.order_id'] = array('gt',0);
        $map = array_merge($map,$map1);
        $where = array_merge($map,$params);
        $cols = "c.car_id";
        $to =  M('cars')->alias('c')
                              ->field($cols)
                              ->join( C('DB_PREFIX') . "order o ON c.car_id=o.car_id")
                              ->join(C('DB_PREFIX')."car_owner as co ON co.owner_id=c.owner_id")
                              // ->join(C('DB_PREFIX')."car_pictures as cp ON cp.car_id=o.car_id")
                              ->where($where)->order('order_id desc')
                              ->buildSql();
        $tot = M()->table($to.' a')->group('car_id')->buildSql();
        $result = M()->table($tot.' b')->count();
        return $result;
    }
    /**
     * 获取车源所属的4s店id
     * @param maxed $params 
     * @return [type] [description]
     */
    // public function getFourId($params){
    //     $float = is_array($params);
    //     if($float){
    //         $map['co.comefrom'] = array('in',$params);
    //     } else{
    //         $map['co.comefrom'] = array('eq',$params);
    //     }
    //     return $map;
    // }
    public function getInfo(){
        //待上拍
        $map1['o.status'] = array('in', array(1,2));
        $map1['c.car_status'] = array('in',array('4','7'));
        $map1['_logic'] = 'or';
        $map11['_complex'] = $map1;
        $info1 = $this->count($map11);
        //拍卖中
        $map2['o.status'] = array('in',array(3,301,4));
        $info2 = $this->count($map2);
        // 待确认
        $map3['o.status'] = array('eq',5);
        $info3 = $this->count($map3);
        // 交易中
        $map4['o.status'] = array('in', array(7,8,9,10,11));
        $info4 = $this->count($map4);
        // 参拍量
        $map5['co.check_date'] = array(array("egt", date('Y-m-01 00:00:00',time())), date('Y-m-t 59:59:59',time()));
        $map5['co.business_status'] = array('notin', array(1,2,3,4,6));
        $info5 = $this->count($map5);
        // 交易成功
        $map6['co.check_date'] = array(array("egt", date('Y-m-01 00:00:00',time())), date('Y-m-t 59:59:59',time()));
        $map6['c.car_status'] = array('eq', 9);
        // $map6['o.status'] = array('eq',13);
        $info6 = $this->count($map6);
        // 交易失败
        $map7['co.check_date'] = array(array("egt", date('Y-m-01 00:00:00',time())), date('Y-m-t 59:59:59',time()));
        $map7['c.car_status'] = array('in', array(2,8));
        $info7 = $this->count($map7);
        //全部车辆
        $info8 = $info1 + $info2;
        //全部订单
        $info9 = $info3 + $info4 + $info6 + $info7;
        $info = array(
                'info1' => $info1,
                'info2' => $info2,
                'info3' => $info3,
                'info4' => $info4,
                'info5' => $info5,
                'info6' => $info6,
                'info7' => $info7,
                'info8' => $info8,
                'info9' => $info9
            );
        // echo M()->getLastSql();
        return $info;
    }

}